package com.gopay.common.cps.dao.gsrt.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.trans.TxnStaCode;
import com.gopay.common.cps.dao.gsrt.GsrtReturnedMoneyMsgSubDao;
import com.gopay.common.domain.gsrt.GsrtReturnedMoneyMsgSub;

/**
 * 
 * @Description: 回款信息子表
 * @author hougn
 * @date 2016年1月27日 上午10:47:51 
 *
 */
@Repository("gsrtReturnedMoneyMsgSubDao")
public class GsrtReturnedMoneyMsgSubDaompl extends BaseDAOImpl<GsrtReturnedMoneyMsgSub, Serializable>
        implements GsrtReturnedMoneyMsgSubDao {

    @Override
    public List<GsrtReturnedMoneyMsgSub> findByReturnedMoneyId(Long returnedMoneyId){
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtReturnedMoneyMsgSub.class);
        criteria.add(Restrictions.eq("returnedMoneyId", returnedMoneyId));
        criteria.add(Restrictions.eq("txnStaCd", TxnStaCode.TXN_STA_CD_20000.value));
        List<GsrtReturnedMoneyMsgSub> list = this.findByCriteria(criteria);
        return list;
    }
    
    @Override
    public List<GsrtReturnedMoneyMsgSub> findAllByReturnedMoneyId(Long returnedMoneyId){
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtReturnedMoneyMsgSub.class);
        criteria.add(Restrictions.eq("returnedMoneyId", returnedMoneyId));
        List<GsrtReturnedMoneyMsgSub> list = this.findByCriteria(criteria);
        return list;
    }
    
    @Override
    public List<GsrtReturnedMoneyMsgSub> findByReturnedMoneyIdAndTxnStaCd(Long returnedMoneyId, int txnStaCd){
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtReturnedMoneyMsgSub.class);
        criteria.add(Restrictions.eq("returnedMoneyId", returnedMoneyId));
        criteria.add(Restrictions.eq("txnStaCd", txnStaCd));
        List<GsrtReturnedMoneyMsgSub> list = this.findByCriteria(criteria);
        return list;
    }
    
    @Override
    public boolean findByMerCustIdAndMerOrderIdIn(String merCustId, List<String> merOrderId){
        DetachedCriteria criteria = DetachedCriteria.forClass(GsrtReturnedMoneyMsgSub.class);
        criteria.add(Restrictions.in("merOrderId", merOrderId));
        criteria.add(Restrictions.eq("merCustId", merCustId));
        return this.findCountByCriteria(criteria) > 0;
    }
}
